package com.kifas.service.dataaccess;

import java.util.Date;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kifas.entity.TransactionJurnalUmumEntity;

@Repository
public class TransactionJurnalDao {

	private static final String ALL_TRANSACTION = "from TransactionJurnamUmumEntity tj ";
	private static final String TRANSACTION_BY_DATE = ALL_TRANSACTION + "where tj.tanggal between :start and :end order by tj.tanggal";
	@Autowired
	private SessionFactory sessionFactory;

	public void insert(TransactionJurnalUmumEntity transactionJurnal)
			throws Exception {
		sessionFactory.getCurrentSession().save(transactionJurnal);
	}

	@SuppressWarnings("unchecked")
	public List<TransactionJurnalUmumEntity> getTransactions(Date start,
			Date end) {
		return sessionFactory.getCurrentSession()
				.createQuery(TRANSACTION_BY_DATE).setDate("start", start)
				.setDate("end", end).list();
	}
}
